package module3;

import com.sun.security.jgss.GSSUtil;

import java.util.*;

public class GamePlay {

    public static void main(String[] args) {

        /**
         * 生成斗地主纸牌 一共54张
         */
        String[] str1 = {"红", "黑", "方", "梅"};//0-3 j
        String[] str2 = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};//0-12 i
        Map map1 = new HashMap();
        map1.put(1, "大王");
        map1.put(2, "小王");
        //System.out.println(map1.size());
        for (int i = 1; i <= 13; i++) {
            for (int j = 1; j <= 4; j++) {
                map1.put(1 + map1.size(), str1[j-1] + str2[i-1]);
            }
        }

        /**
         * 规定纸牌序号  用来模拟大小顺序
         */
        List list1 = new ArrayList();
        for (int i = 1; i <= 54; i++) {
            list1.add(i);
        }
        /*System.out.println(list1);*/
        //System.out.println(map1);
        /**
         * 打乱纸牌顺序
         */
        Collections.shuffle(list1);
        //System.out.println(list1);
        List list2 = new ArrayList();
        List list3 = new ArrayList();
        List list4 = new ArrayList();
        /*List list5 = new ArrayList();*/
        /**
         * 玩家交替摸排
         */
        for (int i = 1; i <= 51; i++) {
            switch (i%3) {
                case 1:
                    list2.add(list1.get(i-1)); break;
                case 2:
                    list3.add(list1.get(i-1));break;
                case 0:
                    list4.add(list1.get(i-1));break;
            }
        }
        /**
         * 最后剩下的三张底牌
         */
        List list5 = list1.subList(51,54);
        /*System.out.println(list1);
        System.out.println(list2);
        System.out.println(list3);
        System.out.println(list4);
        System.out.println(list5);*/
        /*
        按照要求打印三位玩家手里的纸牌顺序并展示三张底牌
         */
        List[] lists ={list2, list3, list4, list5};
        for (int i = 0; i < 4; i++) {
            Collections.sort(lists[i]);
           /* System.out.println(lists[i]);*/
            if (i < 3) {
                System.out.print("第" + (i + 1) + "个人的纸牌顺序是：{ ");
            }else{
                System.out.print("最后的底牌是：{ ");
            }
            for (Object obj : lists[i]) {
                System.out.print(map1.get(obj) + " ");
            }
            System.out.println("}");
        }
    }
}
